# vrp_model.py（增加适应度缓存）
class Customer:
    def __init__(self, id, x, y, demand, volume, early, late):
        self.id = id
        self.x = x
        self.y = y
        self.demand = demand
        self.volume = volume
        self.early = early
        self.late = late

class Vehicle:
    def __init__(self, capacity, volume, max_range,
                 distance_cost=2.5, time_cost=0.5, fixed_cost=500,
                 overload_penalty=1000, time_penalty=200):
        """
        :param distance_cost: 元/公里
        :param time_cost: 元/分钟
        :param fixed_cost: 元/车次
        :param overload_penalty: 超载惩罚元/次
        :param time_penalty: 时间窗违反惩罚元/分钟
        """
        self.capacity = capacity
        self.volume = volume
        self.max_range = max_range
        self.distance_cost = distance_cost
        self.time_cost = time_cost
        self.fixed_cost = fixed_cost
        self.overload_penalty = overload_penalty
        self.time_penalty = time_penalty


class VRPTWInstance:
    def __init__(self, customers, depot, distance_matrix, time_matrix, vehicle):
        self.customers = customers
        self.depot = depot
        self.distance_matrix = distance_matrix  # 距离矩阵（公里）
        self.time_matrix = time_matrix          # 行驶时间矩阵（分钟）
        self.vehicle = vehicle
        self._fitness_cache = {}

    def clear_cache(self):
        self._fitness_cache.clear()